package com.gopay.common.order.dao.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.constants.proccode.ProcCodeEnum;
import com.gopay.common.domain.cps.CpsBatchPayTask;
import com.gopay.common.exception.GopayException;
import com.gopay.common.order.dao.CpsBatchPayTaskQueryDAO;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 批量任务Dao实现类(common-order)
 * 
 * @CpsBatchTaskTargetRelDAOImpl.java
 * @author liuxin
 * @2013-3-5 上午11:50:07 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("cpsBatchPayTaskQueryDAO")
public class CpsBatchPayTaskQueryDAOImpl extends BaseReadDAOImpl<CpsBatchPayTask, Long> implements
        CpsBatchPayTaskQueryDAO {

    @Override
    public CpsBatchPayTask findPayTask(String batchNum, String acctId) throws GopayException{
        String hql = "FROM CpsBatchPayTask where batchNum=:batchNum and payAcct=:payAcct";
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("batchNum", batchNum);
        param.put("payAcct", acctId);

        List<CpsBatchPayTask> list = this.findByHql(hql, param);
        if (list == null || list.size() == 0) {
            return null;
        }
        if(list.size() > 1) {
            throw new GopayException(ProcCodeEnum.PROC_CODE_100E5048);
        }
        return list.get(0);
    }

}
